package com.wisezone.demo0216;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ImgServer {
    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        Socket socket = null;
        try{
            //启动服务端套接字
            serverSocket = new ServerSocket(9099);
            System.out.println("服务端启动成功！！！！！");
            socket = serverSocket.accept();
        }catch (IOException e){
            System.out.println("启动失败！！！！！");
            e.printStackTrace();
        }
        //接收客户端参数
        //读取本地图片
        String srcPath = "img/A01.jpg";
        File fileImg = new File(srcPath);
        try {
            FileInputStream fis = new FileInputStream(fileImg);
            //输出字节流给客户端准备
            OutputStream os = socket.getOutputStream();
            byte[] bytes = new byte[512];
            int len = -1;
            len = fis.read(bytes);
            while (len!=-1){
                os.write(bytes,0,len);
                len=fis.read(bytes);
            }
            os.flush();
            socket.shutdownOutput();

        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){

        }

    }
}
